package test;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class RepairService {
    public static void main(String[] args) {
        JFrame frame = new JFrame("报修服务");
        frame.setDefaultCloseOperation(2);
        frame.setSize(600, 400);
        frame.setLayout(new BorderLayout());
        JPanel topPanel = new JPanel(new GridLayout(3, 2));
        JLabel typeLabel = new JLabel("报修类型：");
        JComboBox<String> typeComboBox = new JComboBox(new String[]{"水电气故障", "设施损坏", "其他"});
        JLabel descriptionLabel = new JLabel("问题描述：");
        JTextArea descriptionArea = new JTextArea(5, 20);
        JLabel contactLabel = new JLabel("联系方式：");
        JTextField contactField = new JTextField(20);
        topPanel.add(typeLabel);
        topPanel.add(typeComboBox);
        topPanel.add(descriptionLabel);
        topPanel.add(new JScrollPane(descriptionArea));
        topPanel.add(contactLabel);
        topPanel.add(contactField);
        JPanel bottomPanel = new JPanel(new FlowLayout(2));
        JButton submitButton = new JButton("提交");
        submitButton.addActionListener((e) -> {
            String type = (String)typeComboBox.getSelectedItem();
            String description = descriptionArea.getText();
            String contact = contactField.getText();
            if (contact != null && !contact.trim().isEmpty()) {
                if (!contact.matches("\\d{11}")) {
                    JOptionPane.showMessageDialog(frame, "联系电话格式不正确，请输入11位数字！", "错误", 0);
                } else {
                    System.out.println("报修类型：" + type);
                    System.out.println("问题描述：" + description);
                    System.out.println("联系方式：" + contact);
                    JOptionPane.showMessageDialog(frame, "报修信息已提交！", "提示", 1);
                }
            } else {
                JOptionPane.showMessageDialog(frame, "联系电话不能为空，请重新输入！", "错误", 0);
            }
        });
        bottomPanel.add(submitButton);
        frame.add(topPanel, "Center");
        frame.add(bottomPanel, "South");
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent windowEvent) {
                MannageService.main((String[])null);
            }
        });
        frame.setVisible(true);
    }
}